package com.yswy.backstage.utils;

import com.yswy.common.utils.IpUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description 字符串工具类
 **/
public class StringUtils {


    public static long toLong(Object obj) {
        return obj == null ? 0l : Long.parseLong(obj.toString());
    }

    public static int obj2Int(Object obj) {
        return obj == null ? 0 : Integer.parseInt(obj.toString());
    }

    public static boolean isEmpty(String str) {
        if (null == str || "".equals(str) || "null".equals(str)) {
            return true;
        }
        return false;
    }

    /**
     * @param url 带分隔的url参数: ?开头
     * @return
     */
    public static Map<String,String> getParam(String url){
        Map<String,String> map = new HashMap<String,String>();
        String params = url.substring(url.indexOf("?") + 1, url.length());
        String[] param =  params.split("&");
        for(String keyvalue:param){
            String[] pair = keyvalue.split("=");
            if(pair.length==2){
                map.put(pair[0], pair[1]);
            }
        }
        return map;
    }



    // cs   FA-16-3E-BA-B3-DF
    // zs   FA-16-3E-C6-FC-6B
    // ccx  18-C0-4D-A0-B7-02
    // mhy  40-B0-76-A3-FD-D9
    public static Boolean isOpenLinux(){
        Map<String,String> map = new HashMap<String,String>();
        map.put("FA-16-3E-BA-B3-DF" , "FA-16-3E-BA-B3-DF");
        map.put("FA-16-3E-C6-FC-6B" , "FA-16-3E-C6-FC-6B");
        //本地需要启用定时任务时打开
//        map.put("18-C0-4D-A0-B7-02" , "18-C0-4D-A0-B7-02");
//        map.put("40-B0-76-A3-FD-D9" , "40-B0-76-A3-FD-D9");
        String mac = IpUtil.getMacId();
        if (map.containsKey(mac)){
            return true;
        }else {
            return false;
        }
    }

    public static Boolean isOpenLinux1(){
        Map<String,String> map = new HashMap<String,String>();
        map.put("FA-16-3E-BA-B3-DF" , "FA-16-3E-BA-B3-DF");
        //本地需要启用定时任务时打开
        map.put("18-C0-4D-A0-B7-02" , "18-C0-4D-A0-B7-02");
        map.put("40-B0-76-A3-FD-D9" , "40-B0-76-A3-FD-D9");
        String mac = IpUtil.getMacId();
        if (map.containsKey(mac)){
            return true;
        }else {
            return false;
        }
    }
}
